package HttpBean.Response;

import java.util.HashMap;
import java.util.Map;

public class ResponseComponent extends Response{
    private static Map<String,Response> component = new HashMap<>();
    static {
        //初始化原型容器
        Response response200 = new Response();
        Response response302 = new Response();
        Response response404 = new Response();
        Response response500 = new Response();
        response200.setLineStatus("200");
        response302.setLineStatus("302");
        response404.setLineStatus("404");
        response500.setLineStatus("500");
        component.put("200", response200);
        component.put("302", response302);
        component.put("404", response404);
        component.put("500", response500);
    }
    public static void add(String str, Response response){
        component.put(str,response);
    }
    public static Response get(String str) {
        Response response = null;
        try {
            response =(Response) component.get(str).clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        try{
            if(response == null) throw new ClassNotFoundException();
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
        return response;
    }
}
